package com.xuz.factory.factory_method.factory;

import com.xuz.factory.factory_method.factory.impl.DiscountFreeGoodsFactory;
import com.xuz.factory.factory_method.factory.impl.SmallGiftFreeGoodsFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 工厂的工厂，用来创建工厂类对象
 * @user 65453
 * @date 2024/9/24 21:58
 */
public class FreeGoodsFactoryMap {
    // 创建map集合，保存工厂对象
    private static final Map<Integer,FreeGoodsFactory> cachedFactories = new HashMap<>();

    static{
        cachedFactories.put(1, new DiscountFreeGoodsFactory());
        cachedFactories.put(2, new SmallGiftFreeGoodsFactory());
    }

    public static FreeGoodsFactory getParserFactory(Integer type){
        if(type == 1){
            return cachedFactories.get(1);
        }else if(type ==2){
            return cachedFactories.get(2);
        }

        return null;
    }
}
